﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace Gfw.Web.Common
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public class SecurityVerifyAttribute : FilterAttribute, IActionFilter
    {


        public void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var v = Params.SecondVerify;
            if (v == false || Params.SecondVerifyTimeOut<DateTime.Now)
            {

                string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;
                string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess);
                filterContext.Result = new RedirectResult("~/User/Security" + redirectUrl);
                return;
            }
            else
            {
                //验证一次以后就失效，哈哈，还是多高级的
               // Params.SecondVerify = false;
            }
        }
    }

}